package com.usian.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.media.WmUserControllerApis;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Auther：DONG on 2021/11/4
 **/
@RestController
@RequestMapping("/api/v1/wmuser")
public class WmUserController implements WmUserControllerApis {

    @Autowired
    private WmUserService wmUserService;

    @Override
    @GetMapping("/findbyname/{name}")
    public WmUser queryWmUserByName(@PathVariable String name) {
        LambdaQueryWrapper<WmUser> lambdaQueryWrapper = Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name);
        List<WmUser> wmUserlist = wmUserService.list(lambdaQueryWrapper);
            if (null!=wmUserlist && !wmUserlist.isEmpty()){
                return wmUserlist.get(0);
            }

        return null;
    }

    @Override
    @PostMapping("/save")
    public boolean saveWmUser(@RequestBody WmUser wmUser) {

        return wmUserService.save(wmUser);
    }
}
